package controllers

import (
	"fmt"

	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"

	"gitee.com/chenrh/finego/backends/models"
)

// BaseController 基类
type BaseController struct {
}

// BeforeActivation called once, before the controller adapted to the main application
// and of course before the server ran.
// After version 9 you can also add custom routes for a specific controller's methods.
// Here you can register custom method's handlers
// use the standard router with `ca.Router` to do something that you can do without mvc as well,
// and add dependencies that will be binded to a controller's fields or method function's input arguments.
func (c *BaseController) BeforeActivation(b mvc.BeforeActivation) {
	fmt.Println("!!!!!")
	anyMiddlewareHere := func(ctx iris.Context) {
		ctx.Application().Logger().Warnf("Inside /custom_path")
		ctx.Next()
	}
	b.Handle("GET", "/custom_path", "CustomHandlerWithoutFollowingTheNamingGuide", anyMiddlewareHere)

	// or even add a global middleware based on this controller's router,
	// which in this example is the root "/":
	// b.Router().Use(myMiddleware)
}

// UserCache 当前用户缓存
func (c *BaseController) UserCache(ctx iris.Context) (bool, models.PUB_USER) {
	return false, models.PUB_USER{}
}

// GetPing2 测试方法
func (c *BaseController) GetPing2(ctx iris.Context) string {
	s1 := ctx.URLParam("s")
	return s1
}
